home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / applic / ntp / depredated / ntp.3.4 / patches / patch10.Z / patch10
Encoding:
Text File  |  1991-09-29  |  25.8 KB  |  908 lines

  1. System: ntp version 3.4
  2. Patch #: 10
  3. Priority: 
  4.  
  5. From:
  6.  
  7. Description:
  8. In the Makefile, remove references to the readclock.c module.
  9.  
  10. New clockhopper supression code.
  11.  
  12. Fix minor problem in ntp.c to get sin_family set in the proper place.
  13. Specify default file for drift value and more peer flag definitions to
  14. reflect various stages of clock selection critera.
  15.  
  16. Add code to count number of peer switches and inhibited peer switches.  Clock
  17. selection code has been updated to reflect 21 April 1989 draft of NTP spec.
  18.  
  19. Add code to save the value of the drift compensation register to a file every
  20. hour.  Add additional configuration file directives which can specify the same
  21. information as on the command line.
  22.  
  23. ntpdc now will display addional peer flags which indicate how far through
  24. the clock selection process a peer was considered.
  25.  
  26.  
  27. Repeat-By:
  28.  
  29. Fix:    From rn, say "| patch -p -N -d DIR", where DIR is your ntp source
  30.     directory.  Outside of rn, say "cd DIR; patch -p -N <thisarticle".
  31.     If you don't have the patch program, apply the following by hand,
  32.     or get patch (version 2.0, latest patchlevel).
  33.  
  34.     After patching:
  35.         make depend
  36.         make
  37.         make install
  38.  
  39.     If patch indicates that patchlevel is the wrong version, you may need
  40.     to apply one or more previous patches, or the patch may already
  41.     have been applied.  See the patchlevel.h file to find out what has or
  42.     has not been applied.  In any event, don't continue with the patch.
  43.  
  44.     If you are missing previous patches they can be obtained from me:
  45.  
  46.     Louis A. Mamakos
  47.     louie@trantor.umd.edu
  48.  
  49.     You can also get the patches via anonymous FTP from
  50.     trantor.umd.edu.
  51.  
  52. Index: patchlevel.h
  53. Prereq: 9
  54. 1c1
  55. < #define PATCHLEVEL 9
  56. ---
  57. > #define PATCHLEVEL 10
  58.  
  59. Index: Makefile
  60. *** Makefile.old    Wed May  3 15:17:41 1989
  61. --- Makefile    Wed May  3 15:17:44 1989
  62. ***************
  63. *** 1,6 ****
  64. ! # $Source: /usr/users/louie/ntp/RCS/Makefile,v $ $Revision: 3.4.1.5 $ $Date: 89/04/10 15:54:19 $
  65.   #
  66.   # $Log:    Makefile,v $
  67.   # Revision 3.4.1.5  89/04/10  15:54:19  louie
  68.   # Add dependency for ntpd.o on ntp.h so things sorta work even without doing a
  69.   # "make depend".  Trash "ci" rule.
  70. --- 1,9 ----
  71. ! # $Source: /usr/users/louie/ntp/RCS/Makefile,v $ $Revision: 3.4.1.6 $ $Date: 89/05/03 15:08:06 $
  72.   #
  73.   # $Log:    Makefile,v $
  74. + # Revision 3.4.1.6  89/05/03  15:08:06  louie
  75. + # In the Makefile, remove references to the readclock.c module.
  76. + # 
  77.   # Revision 3.4.1.5  89/04/10  15:54:19  louie
  78.   # Add dependency for ntpd.o on ntp.h so things sorta work even without doing a
  79.   # "make depend".  Trash "ci" rule.
  80. ***************
  81. *** 106,121 ****
  82.   # Source files
  83.   #
  84.   SRCS=    ntp.c ntpd.c ntpdc.c ntpsubs.c ntp_proto.c ntp_sock.c ntp_adjust.c
  85. ! NTPDSRC= ntpd.c ntpsubs.c ntp_proto.c ntp_sock.c ntp_adjust.c readclock.c
  86.   
  87.   # Object files
  88.   #
  89.   OBJS=    ntp.o ntpd.o ntpdc.o ntpsubs.o ntp_proto.o ntp_sock.o ntp_adjust.o
  90.   NTPDOBJ= ntpd.o ntpsubs.o ntp_proto.o ntp_sock.o ntp_adjust.o
  91. - #
  92. - # if using REFCLOCK
  93. - #
  94. - #NTPDOBJ= ntpd.o ntpsubs.o ntp_proto.o ntp_sock.o ntp_adjust.o readclock.o
  95.   
  96.   DIST= README Makefile man ${SRCS} ${HDRS} ntp.conf test.c extract.pl stat.pl
  97.   PROGS=    ntp ntpd ntpdc ntest
  98. --- 109,120 ----
  99.   # Source files
  100.   #
  101.   SRCS=    ntp.c ntpd.c ntpdc.c ntpsubs.c ntp_proto.c ntp_sock.c ntp_adjust.c
  102. ! NTPDSRC= ntpd.c ntpsubs.c ntp_proto.c ntp_sock.c ntp_adjust.c
  103.   
  104.   # Object files
  105.   #
  106.   OBJS=    ntp.o ntpd.o ntpdc.o ntpsubs.o ntp_proto.o ntp_sock.o ntp_adjust.o
  107.   NTPDOBJ= ntpd.o ntpsubs.o ntp_proto.o ntp_sock.o ntp_adjust.o
  108.   
  109.   DIST= README Makefile man ${SRCS} ${HDRS} ntp.conf test.c extract.pl stat.pl
  110.   PROGS=    ntp ntpd ntpdc ntest
  111.  
  112. Index: README
  113. *** README.old    Wed May  3 15:17:55 1989
  114. --- README    Wed May  3 15:17:58 1989
  115. ***************
  116. *** 1,4 ****
  117. ! README for UNIX NTP release $Date: 89/04/08 10:35:44 $ $Revision: 3.4.1.4 $
  118.   
  119.   
  120.   
  121. --- 1,4 ----
  122. ! README for UNIX NTP release $Date: 89/05/03 15:08:58 $ $Revision: 3.4.1.5 $
  123.   
  124.   
  125.   
  126. ***************
  127. *** 48,53 ****
  128. --- 48,68 ----
  129.       7) Fire up ntpd in /etc/rc.local
  130.   
  131.   History:
  132. + 5/3/89
  133. +     The changes to the ntp_proto.c module for clockhopper suppression have
  134. +     been tweaked once more, ever so slightly to conform with the 21 April
  135. +     1989 draft of the NTP spec.  We won't switch peers if the current 
  136. +     peer makes it into the final selection list, unless the first peer on
  137. +     the selection list is of a higher stratum than the current peer.
  138. +     The ntpd.c/hourly() function now saves the value of the drift
  139. +     compensation register to a file (/etc/ntp.drift by default).  In fact,
  140. +     the last 5 hourly samples are written to the file, as well as how
  141. +     many hours the ntpd process has been running.  Ntpd will also attempt
  142. +     to intialize the value of the drift compensation register from this
  143. +     file when it is started up.  The hourly stats: log message has been
  144. +     augmented to log additional information.
  145.   4/8/89
  146.       Changes to the ntp_proto.c module to supress peer switching when the
  147.       dispersion between the newly selected peer and the currently selected
  148.  
  149. Index: ntp.c
  150. *** ntp.c.old    Wed May  3 15:18:09 1989
  151. --- ntp.c    Wed May  3 15:18:11 1989
  152. ***************
  153. *** 1,9 ****
  154.   #ifndef    lint
  155. ! static char *rcsid = "$Source: /usr/users/louie/ntp/RCS/ntp.c,v $ $Revision: 3.4.1.4 $ $Date: 89/04/07 18:04:49 $";
  156.   #endif    lint
  157.   
  158.   /*
  159.    *  $Log:    ntp.c,v $
  160.    * Revision 3.4.1.4  89/04/07  18:04:49  louie
  161.    * Removed unused variables from ntp.c program.
  162.    * 
  163. --- 1,12 ----
  164.   #ifndef    lint
  165. ! static char *rcsid = "$Source: /usr/users/louie/ntp/RCS/ntp.c,v $ $Revision: 3.4.1.5 $ $Date: 89/05/03 15:09:53 $";
  166.   #endif    lint
  167.   
  168.   /*
  169.    *  $Log:    ntp.c,v $
  170. +  * Revision 3.4.1.5  89/05/03  15:09:53  louie
  171. +  * Fix minor problem in ntp.c to get sin_family set in the proper place.
  172. +  * 
  173.    * Revision 3.4.1.4  89/04/07  18:04:49  louie
  174.    * Removed unused variables from ntp.c program.
  175.    * 
  176. ***************
  177. *** 147,152 ****
  178. --- 150,156 ----
  179.       } else
  180.           dst.sin_port = sp->s_port;
  181.   
  182. +     dst.sin_family = AF_INET;
  183.       while ((n = getopt(argc, argv, "vsf")) != EOF) {
  184.           switch (n) {
  185.           case 'v':
  186. ***************
  187. *** 165,172 ****
  188.   
  189.           if (argv[host] == NULL)
  190.               continue;
  191. -         dst.sin_family = AF_INET;
  192. -         dst.sin_port = sp->s_port;
  193.   
  194.           hp = NULL;
  195.           HostAddr = inet_addr(argv[host]);
  196. --- 169,174 ----
  197.  
  198. Index: ntp.h
  199. *** ntp.h.old    Wed May  3 15:18:22 1989
  200. --- ntp.h    Wed May  3 15:18:26 1989
  201. ***************
  202. *** 1,7 ****
  203. ! /* $Source: /usr/users/louie/ntp/RCS/ntp.h,v $ $Revision: 3.4.1.5 $ $Date: 89/04/10 15:55:42 $ */
  204.   
  205.   /*
  206.    *  $Log:    ntp.h,v $
  207.    * Revision 3.4.1.5  89/04/10  15:55:42  louie
  208.    * Provide default value for number of bits/byte if not defined.  Compute the
  209.    * Window shift mask inside of conditional code on XTAL so we get the correct
  210. --- 1,11 ----
  211. ! /* $Source: /usr/users/louie/ntp/RCS/ntp.h,v $ $Revision: 3.4.1.6 $ $Date: 89/05/03 15:11:06 $ */
  212.   
  213.   /*
  214.    *  $Log:    ntp.h,v $
  215. +  * Revision 3.4.1.6  89/05/03  15:11:06  louie
  216. +  * Specify default file for drift value and more peer flag definitions to
  217. +  * reflect various stages of clock selection critera.
  218. +  * 
  219.    * Revision 3.4.1.5  89/04/10  15:55:42  louie
  220.    * Provide default value for number of bits/byte if not defined.  Compute the
  221.    * Window shift mask inside of conditional code on XTAL so we get the correct
  222. ***************
  223. *** 108,113 ****
  224. --- 112,120 ----
  225.   #ifndef    NTPINITFILE
  226.   #define    NTPINITFILE    "/etc/ntp.conf"
  227.   #endif
  228. + #ifndef    NTPDRIFTCOMP
  229. + #define    NTPDRIFTCOMP    "/etc/ntp.drift"
  230. + #endif
  231.   
  232.   struct list {
  233.       struct ntp_peer *head;
  234. ***************
  235. *** 286,291 ****
  236. --- 293,300 ----
  237.       int    flags;            /* local flags */
  238.   #define    PEER_FL_CONFIG        1
  239.   #define    PEER_FL_AUTHENABLE    2
  240. + #define    PEER_FL_SANE        0x0100    /* sane peer */
  241. + #define    PEER_FL_CANDIDATE    0x0200    /* candidate peer */
  242.   #define    PEER_FL_SYNC        0x1000    /* peer can bet sync'd to */
  243.   #define    PEER_FL_BCAST        0x2000    /* broadcast peer */
  244.   #define    PEER_FL_SELECTED    0x8000    /* actually used by query routine */
  245.  
  246. Index: ntp_proto.c
  247. *** ntp_proto.c.old    Wed May  3 15:18:48 1989
  248. --- ntp_proto.c    Wed May  3 15:18:56 1989
  249. ***************
  250. *** 1,5 ****
  251.   #ifndef    lint
  252. ! static char *rcsid = "$Source: /usr/users/louie/ntp/RCS/ntp_proto.c,v $ $Revision: 3.4.1.8 $ $Date: 89/04/10 15:57:59 $";
  253.   #endif
  254.   
  255.   /*
  256. --- 1,5 ----
  257.   #ifndef    lint
  258. ! static char *rcsid = "$Source: /usr/users/louie/ntp/RCS/ntp_proto.c,v $ $Revision: 3.4.1.9 $ $Date: 89/05/03 15:13:25 $";
  259.   #endif
  260.   
  261.   /*
  262. ***************
  263. *** 11,16 ****
  264. --- 11,20 ----
  265.   
  266.   /*
  267.    * $Log:    ntp_proto.c,v $
  268. +  * Revision 3.4.1.9  89/05/03  15:13:25  louie
  269. +  * Add code to count number of peer switches and inhibited peer switches.  Clock
  270. +  * selection code has been updated to reflect 21 April 1989 draft of NTP spec.
  271. +  * 
  272.    * Revision 3.4.1.8  89/04/10  15:57:59  louie
  273.    * New -l option for ntpd to enable logging for clock adjust messages.  Changed
  274.    * our idea of a bogus packet in the packet procedure to include a packet received
  275. ***************
  276. *** 118,123 ****
  277. --- 122,129 ----
  278.   
  279.   #include "ntp.h"
  280.   
  281. + int peer_switches, peer_sw_inhibited;
  282.   struct ntp_peer dummy_peer;
  283.   extern double WayTooBig;
  284.   extern unsigned long clock_watchdog;
  285. ***************
  286. *** 822,827 ****
  287. --- 828,834 ----
  288.       struct sel_lst {
  289.           struct ntp_peer *peer;
  290.           double distance;
  291. +         double precision;
  292.       } sel_lst[X_NTP_CANDIDATES];
  293.       int i, j, stratums, candidates;
  294.       int sanity_check();
  295. ***************
  296. *** 834,843 ****
  297. --- 841,852 ----
  298.           /*
  299.            * Check if this is a candidate for "sys.peer" 
  300.            */
  301. +         peer->flags &= ~(PEER_FL_SANE | PEER_FL_CANDIDATE);
  302.           if(sanity_check(peer)) {
  303.               sel_lst[candidates].peer = peer;
  304.               sel_lst[candidates].distance = peer->estdisp + 
  305.                   s_fixed_to_double(&peer->dispersion);
  306. +             peer->flags |= PEER_FL_SANE;
  307.               candidates++;
  308.           }
  309.           peer = peer->next;
  310. ***************
  311. *** 944,949 ****
  312. --- 953,959 ----
  313.       }
  314.       while (candidates > 1) {
  315.           double maxdispersion = 0.0, dispersion, weight;
  316. +         double min_precision_thres = 10e20, precision_thres;
  317.           short worst = 0;    /* shut up GNU CC about unused var */
  318.   #ifdef    DEBUG
  319.           if (debug > 3)
  320. ***************
  321. *** 954,959 ****
  322. --- 964,970 ----
  323.                  rest of the candidates */
  324.               dispersion = 0.0;
  325.               weight = 1.0;
  326. +             sel_lst[i].peer->flags |= PEER_FL_CANDIDATE;
  327.               for (j = 0; j < candidates; j++) {
  328.                   dtmp = sel_lst[j].peer->estoffset -
  329.                       sel_lst[i].peer->estoffset;
  330. ***************
  331. *** 965,983 ****
  332.               /* since we just happen to have this double floating
  333.                  around.. */
  334.               sel_lst[i].distance = dispersion;
  335.               if (dispersion >= maxdispersion) {
  336.                   maxdispersion = dispersion;
  337.                   worst = i;
  338.               }
  339.   #ifdef    DEBUG
  340.               if (debug > 4) {
  341. !                 printf(" peer %s => disp %f\n",
  342.                          ntoa(sel_lst[i].peer->src.sin_addr),
  343. !                        dispersion);
  344.               }
  345.   #endif
  346.           }
  347.   #ifdef    DEBUG
  348.           if (debug > 4)
  349.               printf(" peer %s => TOSS\n",
  350.                      ntoa(sel_lst[worst].peer->src.sin_addr));
  351. --- 976,1018 ----
  352.               /* since we just happen to have this double floating
  353.                  around.. */
  354.               sel_lst[i].distance = dispersion;
  355. +             
  356. +             precision_thres = NTP_MAXSKW + 1.0/(1<<-sys.precision);
  357. +             if (peer->precision < 0 &&
  358. +                 -peer->precision < sizeof(long)*NBBY)
  359. +                 precision_thres += 1.0/(1<<-peer->precision);
  360. +             sel_lst[i].precision = precision_thres;
  361.               if (dispersion >= maxdispersion) {
  362.                   maxdispersion = dispersion;
  363.                   worst = i;
  364.               }
  365. +             if (precision_thres < min_precision_thres) {
  366. +                 min_precision_thres = precision_thres;
  367. +             }
  368.   #ifdef    DEBUG
  369.               if (debug > 4) {
  370. !                 printf(" peer %s => disp %f prec_th %f\n",
  371.                          ntoa(sel_lst[i].peer->src.sin_addr),
  372. !                        dispersion, precision_thres);
  373.               }
  374.   #endif
  375.           }
  376. +         /*
  377. +          *  Now check to see if the max dispersion is greater than
  378. +          *  the min dispersion limit.  If so, crank again, otherwise
  379. +          *  bail out.
  380. +          */
  381. +         if (! (maxdispersion > min_precision_thres)) {
  382.   #ifdef    DEBUG
  383. +             if (debug > 4)
  384. +                 printf(" %d left valid\n", candidates);
  385. + #endif
  386. +             break;
  387. +         }
  388. +             
  389. + #ifdef    DEBUG
  390.           if (debug > 4)
  391.               printf(" peer %s => TOSS\n",
  392.                      ntoa(sel_lst[worst].peer->src.sin_addr));
  393. ***************
  394. *** 987,992 ****
  395. --- 1022,1028 ----
  396.            *  and interate until there is only one candidate peer left.
  397.            */
  398.           if (worst != candidates - 1) {
  399. +             sel_lst[worst].peer->flags &= ~PEER_FL_CANDIDATE;
  400.               for (i = worst, j = worst + 1; j < candidates; )
  401.                   sel_lst[i++].peer = sel_lst[j++].peer;
  402.           }
  403. ***************
  404. *** 997,1038 ****
  405.       if (debug > 3)
  406.           printf("select_clock: step6 %d candidates\n", candidates);
  407.   #endif
  408. -     if (sys.peer != NULL && sys.peer != sel_lst[0].peer) {
  409. -         /* 
  410. -          * Potential peer is different that current one; don't switch
  411. -          * to new peer unless the offset is suitably "large".
  412. -          */
  413. -         if (sys.peer->stratum == sel_lst[0].peer->stratum) {
  414. -             double threshold ;
  415.   
  416. !             threshold = NTP_MAXSKW +
  417. !                 1.0/(unsigned long)(1L << -sys.precision);
  418. !             /* make sure we don't try to divide by zero */
  419. !             if (-sel_lst[0].peer->precision < sizeof(long)*NBBY)
  420. !                 threshold += 1.0/(unsigned long)
  421. !                     (1L << -sel_lst[0].peer->precision);
  422. !             if (sel_lst[0].peer->estoffset < threshold) {
  423. ! #ifdef    DEBUG
  424. !                 if (debug > 2)
  425. !                     printf("clock: inhibit peer switch\n");
  426. ! #endif
  427.                   return;
  428.               }
  429. !         }         
  430.       }
  431.   
  432. ! #ifdef    DEBUG
  433. !     if ((debug > 2) || (sys.peer != sel_lst[0].peer))
  434. !         printf("clock: select peer %s stratum %d\n",
  435. !                ntoa(sel_lst[0].peer->src.sin_addr),
  436. !                sel_lst[0].peer->stratum);
  437. ! #endif
  438. !     /* 
  439. !      *  We've finally selected our best bet for a clock to synchronize to.
  440.        */
  441.       if (sys.peer != sel_lst[0].peer) {
  442.           if (sys.peer != NULL)
  443.               syslog(LOG_INFO, "clock: select peer %s stratum %d was %s stratum %d",
  444. --- 1033,1072 ----
  445.       if (debug > 3)
  446.           printf("select_clock: step6 %d candidates\n", candidates);
  447.   #endif
  448.   
  449. !     /*
  450. !      *  Check to see if current peer is on the list of candidate peers.  If
  451. !      *  don't change sys.peer.  Note that if the first selected clock is
  452. !      *  at a higher stratum, don't even bother; we're going to want to
  453. !      *  switch to it.
  454. !      */
  455. !     if (sys.peer != NULL && 
  456. !         (sys.peer->stratum > sel_lst[0].peer->stratum)) {
  457. !         for (i = 0; i < candidates; i++) {
  458. !             if (sys.peer == sel_lst[i].peer) {
  459. !                 /*
  460. !                  * The clock we're currently synchronized to
  461. !                  * is among the candidate peers.  Don't switch.
  462. !                  */
  463. !                 if (i != 0) {
  464. !                     /*
  465. !                      *  Count instances where the best 
  466. !                      *  candidate is different from the
  467. !                      *  current clock, thus inhibiting
  468. !                      *  clockhopping.
  469. !                      */
  470. !                     peer_sw_inhibited++;
  471. !                 }
  472.                   return;
  473.               }
  474. !         }
  475.       }
  476.   
  477. !     /*
  478. !      *  The currently selected peer (if any) isn't on the candidate list.
  479. !      *  Grab the first one and let it be.
  480.        */
  481.       if (sys.peer != sel_lst[0].peer) {
  482.           if (sys.peer != NULL)
  483.               syslog(LOG_INFO, "clock: select peer %s stratum %d was %s stratum %d",
  484. ***************
  485. *** 1043,1053 ****
  486.               syslog(LOG_INFO, "clock: select peer %s stratum %d was UNSYNCED",
  487.                      ntoa(sel_lst[0].peer->src.sin_addr),
  488.                      sel_lst[0].peer->stratum);
  489.       }
  490. -     /* finally, set new peer */
  491. -     sys.peer = sel_lst[0].peer;
  492.   }
  493.   
  494.   int
  495. --- 1077,1092 ----
  496.               syslog(LOG_INFO, "clock: select peer %s stratum %d was UNSYNCED",
  497.                      ntoa(sel_lst[0].peer->src.sin_addr),
  498.                      sel_lst[0].peer->stratum);
  499. +         
  500. + #ifdef    DEBUG
  501. +         if (debug > 2)
  502. +             printf("clock: select peer %s stratum %d of %d cand\n",
  503. +                    ntoa(sel_lst[0].peer->src.sin_addr),
  504. +                    sel_lst[0].peer->stratum, candidates);
  505. + #endif
  506. +         sys.peer = sel_lst[0].peer;
  507. +         peer_switches++;
  508.       }
  509.   }
  510.   
  511.   int
  512.  
  513. Index: ntpd.c
  514. *** ntpd.c.old    Wed May  3 15:19:23 1989
  515. --- ntpd.c    Wed May  3 15:19:31 1989
  516. ***************
  517. *** 1,9 ****
  518.   #ifndef    lint
  519. ! static char *rcsid = "$Source: /usr/users/louie/ntp/RCS/ntpd.c,v $ $Revision: 3.4.1.7 $ $Date: 89/04/10 15:58:45 $";
  520.   #endif    lint
  521.   
  522.   /*
  523.    *  $Log:    ntpd.c,v $
  524.    * Revision 3.4.1.7  89/04/10  15:58:45  louie
  525.    * Add -l option to enable logging of clock adjust messages.
  526.    * 
  527. --- 1,14 ----
  528.   #ifndef    lint
  529. ! static char *rcsid = "$Source: /usr/users/louie/ntp/RCS/ntpd.c,v $ $Revision: 3.4.1.8 $ $Date: 89/05/03 15:16:17 $";
  530.   #endif    lint
  531.   
  532.   /*
  533.    *  $Log:    ntpd.c,v $
  534. +  * Revision 3.4.1.8  89/05/03  15:16:17  louie
  535. +  * Add code to save the value of the drift compensation register to a file every
  536. +  * hour.  Add additional configuration file directives which can specify the same
  537. +  * information as on the command line.
  538. +  * 
  539.    * Revision 3.4.1.7  89/04/10  15:58:45  louie
  540.    * Add -l option to enable logging of clock adjust messages.
  541.    * 
  542. ***************
  543. *** 115,120 ****
  544. --- 120,127 ----
  545.   char *prog_name;
  546.   
  547.   char *conf = NTPINITFILE;
  548. + char *driftcomp_file = NTPDRIFTCOMP;
  549. + static int drift_fd = -1;
  550.   
  551.   #ifdef    DEBUG
  552.   int debug = 0;
  553. ***************
  554. *** 275,286 ****
  555.           setlogmask(LOG_UPTO(LOG_INFO));
  556.   #endif    /* LOG_DAEMON */
  557.   
  558. !     syslog(LOG_NOTICE, "%s version $Revision: 3.4.1.7 $", prog_name);
  559.       syslog(LOG_NOTICE, "patchlevel %d", PATCHLEVEL);
  560.   
  561.   #ifdef    DEBUG
  562.       if (debug)
  563. !         printf("%s version $Revision: 3.4.1.7 $ patchlevel %d\n",
  564.                  prog_name, PATCHLEVEL);
  565.   #endif
  566.       (void) setpriority(PRIO_PROCESS, 0, -10);
  567. --- 282,293 ----
  568.           setlogmask(LOG_UPTO(LOG_INFO));
  569.   #endif    /* LOG_DAEMON */
  570.   
  571. !     syslog(LOG_NOTICE, "%s version $Revision: 3.4.1.8 $", prog_name);
  572.       syslog(LOG_NOTICE, "patchlevel %d", PATCHLEVEL);
  573.   
  574.   #ifdef    DEBUG
  575.       if (debug)
  576. !         printf("%s version $Revision: 3.4.1.8 $ patchlevel %d\n",
  577.                  prog_name, PATCHLEVEL);
  578.   #endif
  579.       (void) setpriority(PRIO_PROCESS, 0, -10);
  580. ***************
  581. *** 312,317 ****
  582. --- 319,331 ----
  583.       init_kern_vars();
  584.       init_logical_clock();
  585.   
  586. +     /*
  587. +      * Attempt to open for writing the file for storing the drift comp
  588. +      * register.  File must already exist for snapshots to be taken.
  589. +      */
  590. +     if ((i = open(driftcomp_file, O_WRONLY|O_CREAT, 0644)) >= 0) {
  591. +         drift_fd = i;
  592. +     }
  593.       (void) gettimeofday(&tv, (struct timezone *) 0);
  594.       srand(tv.tv_sec);
  595.   
  596. ***************
  597. *** 627,646 ****
  598.       register struct ntp_peer *peer = peer_list.head, *next;
  599.   #ifndef    XADJTIME2
  600.       extern void adj_host_clock();
  601. - #endif
  602.   
  603. ! #ifdef    REFCLOCK
  604. !     /*
  605. !      *  I think that this is being done wrong.  The reference clock 
  606. !      *  attached to this host should look like another peer.  Then the
  607. !      *  normal clock selection stuff will select the "right" one.
  608. !      */
  609. !     if (sys.stratum == 1)
  610. !         adj_from_source();
  611. !     else
  612. ! #endif    /* REFCLOCK */
  613. ! #ifndef    XADJTIME2
  614. !         adj_host_clock();
  615.   #endif
  616.       /*
  617.        * Count down sys.hold if necessary.
  618. --- 641,648 ----
  619.       register struct ntp_peer *peer = peer_list.head, *next;
  620.   #ifndef    XADJTIME2
  621.       extern void adj_host_clock();
  622.   
  623. !     adj_host_clock();
  624.   #endif
  625.       /*
  626.        * Count down sys.hold if necessary.
  627. ***************
  628. *** 720,725 ****
  629. --- 722,729 ----
  630.       int i;
  631.       int debuglevel;
  632.       int stagger = 0;
  633. +     double j;
  634. +     extern double drift_comp;
  635.   
  636.       bzero((char *) &sin, sizeof(sin));
  637.       fp = fopen(config, "r");
  638. ***************
  639. *** 747,753 ****
  640.                   } else
  641.                       trusting = atoi(name);
  642.               }
  643. !         } else if (strcmp(name, "debuglevel") == 0) {
  644.               if (fscanf(fp, "%d", &debuglevel) != 1)
  645.                   error = TRUE;
  646.   #ifdef    DEBUG
  647. --- 751,785 ----
  648.                   } else
  649.                       trusting = atoi(name);
  650.               }
  651. !         } else if (strcmp(name, "logclock") == 0) {
  652. !             if (fscanf(fp, "%s", name) != 1)
  653. !                 error = TRUE;
  654. !             else {
  655. !                 if (*name == 'Y' || *name == 'y') {
  656. !                     logstats = 1;
  657. !                 } else if (*name == 'N' || *name == 'n') {
  658. !                     logstats = 0;
  659. !                 } else
  660. !                     logstats = atoi(name);
  661. !             }
  662. !         } else if (strcmp(name, "driftfile") == 0) {
  663. !             if (fscanf(fp, "%s", name) != 1)
  664. !                 error = TRUE;
  665. !             else {
  666. !                 if (driftcomp_file = malloc(strlen(name)+1))
  667. !                     strcpy(driftcomp_file, name);
  668. !             }
  669. !         } else if (strcmp(name, "waytoobig") == 0 ||
  670. !                strcmp(name, "setthreshold") == 0) {
  671. !             if (fscanf(fp, "%s", name) != 1)
  672. !                 error = TRUE;
  673. !             else {
  674. !                 if (strcmp(name, "any") == 0)
  675. !                     WayTooBig = 10e15;
  676. !                 else
  677. !                     WayTooBig = atof(name);
  678. !             }
  679. !         } else if (strncmp(name, "debuglevel", 5) == 0) {
  680.               if (fscanf(fp, "%d", &debuglevel) != 1)
  681.                   error = TRUE;
  682.   #ifdef    DEBUG
  683. ***************
  684. *** 754,771 ****
  685.               else debug += debuglevel;
  686.   #endif
  687.           } else if (strcmp(name, "stratum") == 0) {
  688. !             if (fscanf(fp, "%d", &stratum) != 1)
  689. !                 error = TRUE;
  690. !             else sys.stratum = (u_char) stratum;
  691. !             if (sys.stratum == 1) {
  692. !                 if (fscanf(fp, "%4s", ref_clock) != 1)
  693. !                     error = TRUE;
  694. !                 else {
  695. !                     ref_clock[4] = 0;
  696. !                     (void) strncpy((char *) &sys.refid,
  697. !                                ref_clock, 4);
  698. !                 }
  699. !             }
  700.           } else if (strcmp(name, "precision") == 0) {
  701.               if (fscanf(fp, "%d", &precision) != 1)
  702.                   error = TRUE;
  703. --- 786,793 ----
  704.               else debug += debuglevel;
  705.   #endif
  706.           } else if (strcmp(name, "stratum") == 0) {
  707. !             fprintf(stderr, "Obsolete command 'stratum'\n");
  708. !             error = TRUE;
  709.           } else if (strcmp(name, "precision") == 0) {
  710.               if (fscanf(fp, "%d", &precision) != 1)
  711.                   error = TRUE;
  712. ***************
  713. *** 775,780 ****
  714. --- 797,813 ----
  715.               if (fscanf(fp, "%d", &i) != 1)
  716.                   error = TRUE;
  717.               else tickadj = i;
  718. +         } else if (strcmp(name, "settickadj") == 0) {
  719. +             if (fscanf(fp, "%s", name) != 1)
  720. +                 error = TRUE;
  721. +             else {
  722. +                 if (*name == 'Y' || *name == 'y') {
  723. +                     dotickadj = 1;
  724. +                 } else if (*name == 'N' || *name == 'n') {
  725. +                     dotickadj = 0;
  726. +                 } else
  727. +                     dotickadj = atoi(name);
  728. +             }
  729.   #endif
  730.   #ifdef    NOSWAP
  731.           } else if (strcmp(name, "noswap") == 0) {
  732. ***************
  733. *** 915,920 ****
  734. --- 948,969 ----
  735.   
  736.           exit(1);
  737.       }
  738. +     /*
  739. +      *  Read saved drift compensation register value.
  740. +      */
  741. +     if ((fp = fopen(driftcomp_file, "r")) != NULL) {
  742. +         if (fscanf(fp, "%f", &j) == 1 && j > -1.0 && j < 1.0) {
  743. +             drift_comp = j;
  744. +             syslog(LOG_INFO,
  745. +                    "Drift compensation value initialized to %f", j);
  746. +         } else {
  747. +             fprintf(stderr,
  748. +                 "init_ntp: bad drift compensation value\n");
  749. +             syslog(LOG_ERR,
  750. +                    "init_ntp: bad drift compensation value\n");
  751. +         }
  752. +         fclose(fp);
  753. +     }
  754.   }
  755.   
  756.   int kern_tickadj, kern_hz, kern_tick;
  757. ***************
  758. *** 1168,1183 ****
  759.   hourly() {
  760.       char buf[200];
  761.       register int p = 0;
  762.       extern double drift_comp, compliance;
  763.   
  764. !     (void) sprintf(buf, "stats: dc %f comp %f", drift_comp, compliance);
  765.   
  766.       if (sys.peer == NULL)
  767.           strcat(buf, " UNSYNC");
  768.       else {
  769.           p = strlen(buf);
  770. !         (void) sprintf(buf + p, " SYNC %s %d",
  771. !             ntoa(sys.peer->src.sin_addr), sys.peer->stratum);
  772.       }
  773.       syslog(LOG_INFO, buf);
  774.   #ifdef    DEBUG
  775. --- 1217,1239 ----
  776.   hourly() {
  777.       char buf[200];
  778.       register int p = 0;
  779. +     static double drifts[5] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
  780. +     static int drift_count = 0;
  781.       extern double drift_comp, compliance;
  782. +     extern int peer_switches, peer_sw_inhibited;
  783.   
  784. !     (void) sprintf(buf, "stats: dc %f comp %f peersw %d inh %d",
  785. !                drift_comp, compliance, peer_switches,
  786. !                peer_sw_inhibited);
  787.   
  788.       if (sys.peer == NULL)
  789.           strcat(buf, " UNSYNC");
  790.       else {
  791.           p = strlen(buf);
  792. !         (void) sprintf(buf + p, " off %f SYNC %s %d",
  793. !                    sys.peer->estoffset,
  794. !                    ntoa(sys.peer->src.sin_addr),
  795. !                    sys.peer->stratum);
  796.       }
  797.       syslog(LOG_INFO, buf);
  798.   #ifdef    DEBUG
  799. ***************
  800. *** 1184,1189 ****
  801. --- 1240,1269 ----
  802.       if (debug)
  803.           puts(buf);
  804.   #endif
  805. +     /*
  806. +      *  If the drift compensation snapshot file is open, then write
  807. +      *  the current value to it.  Since there's only one block in the
  808. +      *  file, and no one else is reading it, we'll just keep the file
  809. +      *  open and write to it.
  810. +      */
  811. +     if (drift_fd >= 0) {
  812. +         drifts[drift_count % 5] = drift_comp;
  813. +         /* works out to be 70 bytes */
  814. +         (void) sprintf(buf,
  815. +              "%+12.10f %+12.10f %+12.10f %+12.10f %+12.10f %4d\n",
  816. +                    drifts[drift_count % 5],
  817. +                    drifts[(drift_count+4) % 5],
  818. +                    drifts[(drift_count+3) % 5],
  819. +                    drifts[(drift_count+2) % 5],
  820. +                    drifts[(drift_count+1) % 5],
  821. +                    drift_count + 1);
  822. +         (void) lseek(drift_fd, 0L, L_SET);
  823. +         if (write(drift_fd, buf, strlen(buf)) < 0) {
  824. +             syslog(LOG_ERR, "Error writing drift comp file: %m");
  825. +         }
  826. +         drift_count++;
  827. +     }
  828.   }
  829.   
  830.   #if    defined(DEBUG) && defined(SIGUSR1) && defined(SIGUSR2)
  831.  
  832. Index: ntpdc.c
  833. *** ntpdc.c.old    Wed May  3 15:19:48 1989
  834. --- ntpdc.c    Wed May  3 15:19:51 1989
  835. ***************
  836. *** 1,9 ****
  837.   #ifndef    lint
  838. ! static char *RCSid = "$Source: /usr/users/louie/ntp/RCS/ntpdc.c,v $ $Revision: 3.4.1.5 $ $Date: 89/04/08 10:38:06 $";
  839.   #endif
  840.   
  841.   /*
  842.    * $Log:    ntpdc.c,v $
  843.    * Revision 3.4.1.5  89/04/08  10:38:06  louie
  844.    * Minor cosmetic changes and removed dead debug code from ntpd.c
  845.    * 
  846. --- 1,13 ----
  847.   #ifndef    lint
  848. ! static char *RCSid = "$Source: /usr/users/louie/ntp/RCS/ntpdc.c,v $ $Revision: 3.4.1.6 $ $Date: 89/05/03 15:17:27 $";
  849.   #endif
  850.   
  851.   /*
  852.    * $Log:    ntpdc.c,v $
  853. +  * Revision 3.4.1.6  89/05/03  15:17:27  louie
  854. +  * ntpdc now will display addional peer flags which indicate how far through
  855. +  * the clock selection process a peer was considered.
  856. +  * 
  857.    * Revision 3.4.1.5  89/04/08  10:38:06  louie
  858.    * Minor cosmetic changes and removed dead debug code from ntpd.c
  859.    * 
  860. ***************
  861. *** 287,292 ****
  862. --- 291,297 ----
  863.       double offset[PEER_SHIFT], delay[PEER_SHIFT], dsp,del,off;
  864.       char c;
  865.       char *cvthname();
  866. +     int flags;
  867.   
  868.       sin.sin_addr.s_addr = n->net_address;
  869.       for (i = 0; i < PEER_SHIFT; i++) {
  870. ***************
  871. *** 297,305 ****
  872.       del = (long) ntohl(n->estdelay);    /* leave in milliseconds */
  873.       off = (long) ntohl(n->estoffset);    /* leave in milliseconds */
  874.       c = ' ';
  875. !     if (ntohs(n->flags) & PEER_FL_CONFIG)
  876.           c = '-';        /* mark pre-configured */
  877. !     if (ntohs(n->flags) & PEER_FL_SELECTED)
  878.           c = '*';        /* mark peer selection */
  879.       sin.sin_addr.s_addr = n->net_address;
  880.       printf("%c%-15.15s ", c, cvthname(&sin));
  881. --- 302,315 ----
  882.       del = (long) ntohl(n->estdelay);    /* leave in milliseconds */
  883.       off = (long) ntohl(n->estoffset);    /* leave in milliseconds */
  884.       c = ' ';
  885. !     flags = ntohs(n->flags);
  886. !     if (flags & PEER_FL_CONFIG)
  887.           c = '-';        /* mark pre-configured */
  888. !     if (flags & PEER_FL_SANE)
  889. !         c = '.';        /* passed sanity check */
  890. !     if (flags & PEER_FL_CANDIDATE)
  891. !         c = '+';        /* made candidate list */
  892. !     if (flags & PEER_FL_SELECTED)
  893.           c = '*';        /* mark peer selection */
  894.       sin.sin_addr.s_addr = n->net_address;
  895.       printf("%c%-15.15s ", c, cvthname(&sin));
  896.